package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* AboutView
* */
class AboutView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mStrokeWidth1 = context.resources.getDimension(R.dimen.dp_2)

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeWidth = mStrokeWidth1
            style = Paint.Style.STROKE
            color = context.resources.getColor(R.color.color_CF2432)
        }
    }

    private val mPaint1 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            color = context.resources.getColor(R.color.color_CF2432)
        }
    }

    private val mPaint2 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeCap = Paint.Cap.ROUND
            style = Paint.Style.STROKE
            color = context.resources.getColor(R.color.color_CF2432)
        }
    }

    private val mPath2 by lazy {
        Path()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            translate(cx, cy)

            drawCircle(
                0F,
                0F,
                cx * 7 / 8,
                mPaint0
            )

            drawCircle(
                0F,
                -cy * 12 / 25,
                cy / 10,
                mPaint1
            )

            mPaint2.strokeWidth = cy / 10
            mPath2.apply {
                reset()
                moveTo(0F, -cy * 12 / 25 + cy / 10 * 27 / 12)
                lineTo(0F,cy * 7 / 8 - (cy * 7 / 8 - cy * 12 / 25 - cy / 10))
            }
            drawPath(mPath2, mPaint2)
        }
    }
}